package org.example.erat.service;

import org.example.erat.service.parser.CsvParser;
import org.example.erat.service.parser.ExcelParser;
import org.example.erat.service.parser.FileParser;
import org.springframework.web.multipart.MultipartFile;

public class FileParserFactory {
    public static FileParser createParser(MultipartFile file) {
        String filename = file.getOriginalFilename();
        if (filename == null) throw new InvalidFileNameException("文件名为空");

        if (filename.endsWith(".xlsx") || filename.endsWith(".xls")) {
            return new ExcelParser();
        } else if (filename.endsWith(".csv")) {
            return new CsvParser();
        } else {
            throw new InvalidFileNameException("不支持的文件类型");
        }
    }
}
